package com.example.chat.navigation

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.platform.LocalConfiguration
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import androidx.navigation.navigation
import com.example.chat.view.LayoutConstraints
import com.example.chat.view.TopicDetailScreen
import com.example.chat.view.TopicListScreen
import com.example.chat.view.TopicSettingScreen
import com.example.chat.viewmodel.TopicDetailViewModel
import com.example.chat.viewmodel.TopicListViewModel
import com.example.featuresdk.analytics.ScreenAnalytics

@ExperimentalFoundationApi
fun NavGraphBuilder.chatNestedNavigationGraph(navHostController: NavHostController, featureKey: String) {

    NavigationController.instance.navController = navHostController

    navigation(startDestination = Screen.TopicList.route, route = featureKey) {

        composable(Screen.TopicList.route) {
            val viewModel: TopicListViewModel = hiltViewModel()
            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)
            ScreenAnalytics(screenName = "TopicListScreen") {
                TopicListScreen(viewModel.uiState, uiConstraints)
            }
        }

        composable(Screen.TopicDetail.route,
            arguments = listOf(navArgument("id"){ type = NavType.LongType})){
            val viewModel: TopicDetailViewModel = hiltViewModel()
            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)
            ScreenAnalytics(screenName = "TopicDetailScreen") {
                TopicDetailScreen(viewModel.uiState, uiConstraints, viewModel.uiCommands)
            }
        }

        composable(Screen.TopicSetting.route,
            arguments = listOf(navArgument("id"){ type = NavType.LongType})){
            val uiConstraints = LayoutConstraints.init(LocalConfiguration.current)
            TopicSettingScreen(uiConstraints)
        }
    }
}